<?php
// $Id: template.php,v 1.16.2.1 2009/02/25 11:47:37 goba Exp $

/**
 * Return a themed breadcrumb trail.
 */
function KeyTheme_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function KeyTheme_preprocess_page(&$vars) {
  $vars['tabs2'] = menu_secondary_local_tasks();
}

/**
 * Theme the menu
 */
function KeyTheme_menu_local_tasks() {
  return menu_primary_local_tasks();
}

function KeyTheme_comment_submitted($comment) {
  return t('!datetime — !username',
    array(
      '!username' => theme('username', $comment),
      '!datetime' => format_date($comment->timestamp)
    ));
}


/**
* Add easy classes/id's to menu items
*/
function KeyTheme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty($extra_class)) {
    $class .= ' '. $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active-trail';
  }
 
  // Add unique identifier
  static $item_id = 0;
  $item_id += 1;
  $id .= ' ' . 'menu-item-custom-id-' . $item_id;
  // Add semi-unique class
  $class .= ' ' . preg_replace("/[^a-zA-Z0-9]/", "", strip_tags($link));
 
  return '<li class="'. $class .'" id="' . $id . '">'. $link . $menu ."</li>\n";
}

/**
* Adds a meta line that tells users they're logged in
*/
function KeyTheme_user_id_bar() {
	
	global $user;
		if ($user->uid) {
			print '<div id="UserIDContainer" class="LoggedIn"><div id="UserID">';
			print "You are logged in as <a href='". base_path() ."user/" . $user->uid . "'> "  . $user->name . "</a> | ";
			print l("Log Out ","logout");
		}
		else {
			print '<div id="UserIDContainer" class="NotLoggedIn"><div id="UserID">';
			print l("Login ","user");
		}
	print '</div><!-- /UserID --></div><!-- /UserIDContainer -->';
}


function KeyTheme_whereami() {

	// create an array based on the current path
	$url = $_SERVER['REQUEST_URI'];
	$mypath = explode("/",$url);
	// tell me which subdirectory I'm in
	
	if ($mypath[1] != '') {
		echo $mypath[1] . ' ';
	}

}


// Breakout vocabularies into separate arrays
function KeyTheme_preprocess_node(&$vars) {
  // If we have any terms...
  if ($vars['node']->taxonomy) {
    // Let's iterate through each term.
    foreach ($vars['node']->taxonomy as $term) {
      // We will build a new array where there will be as many
      // nested arrays as there are vocabularies
      // The key for each nested array is the vocabulary ID.     
      $vocabulary[$term->vid]['taxonomy_term_'. $term->tid]  = array(
         'title' => $term->name,
         'href' => taxonomy_term_path($term),
         'attributes' => array(
         'rel' => 'tag', 
         'title' => strip_tags($term->description),
        ),
      );       
    }
    $vars['vocab1']= theme('links',$vocabulary[1], array('class'=>'links inline'));
    $vars['vocab2']= theme('links',$vocabulary[2], array('class'=>'links inline'));
    $vars['vocab3']= theme('links',$vocabulary[3], array('class'=>'links inline'));
  }
}


/*
function KeyTheme_node_submitted($node) {

  return t('Posted by !username on @date', array(
	'!comments' => $comment_count;
    '!username' => theme('username', $node),
    '@date' => format_date($node->created, 'custom', 'd M Y')
  ));
}
*/



function KeyTheme_node_submitted($node){

$output .= user_load(array('name' => $node->uid));
  $output .= '<div class="meta-date">' . format_date($node->created, 'custom', 'd M Y') . '</div>';
  $output .= '<div class="meta-author">by ' . t('!username',
    array(
    '!username' => theme('username', $node),
    )) . '</div>';
  if($node->comment_count ){
    $title = format_plural($node->comment_count, t('1 comment'), t('@count comments'));
    $comment_link = l($title, 'node/'. $node->nid, array('fragment' => 'comments'));
    $output .= '<div class="meta-comments">'.  $comment_link .'</div>';
  }

  return $output; 
}


